package com.runvp.rest.biz;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.runvp.common.annotation.Log;
import com.runvp.common.enums.BusinessType;
import com.runvp.service.biz.domain.BizCustomerRecharge;
import com.runvp.service.biz.service.IBizCustomerRechargeService;
import com.runvp.common.core.controller.BaseController;
import com.runvp.common.core.domain.AjaxResult;
import com.runvp.common.utils.poi.ExcelUtil;
import com.runvp.common.annotation.ParamValid;
import com.runvp.common.core.page.TableDataInfo;

/**
 * 用户充值Controller
 * 
 * @author runvp
 * @date 2022-11-15
 */
@Controller
@RequestMapping("/biz/recharge")
public class BizCustomerRechargeController extends BaseController {
    private String prefix = "biz/recharge";

    @Autowired
    private IBizCustomerRechargeService bizCustomerRechargeService;

    @RequiresPermissions("biz:recharge:view")
    @GetMapping()
    public String recharge() {
        return prefix + "/recharge";
    }

    /**
     * 查询用户充值列表
     */
    @RequiresPermissions("biz:recharge:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizCustomerRecharge bizCustomerRecharge) {
        startPage();
        List<BizCustomerRecharge> list = bizCustomerRechargeService.selectBizCustomerRechargeList(bizCustomerRecharge);
        return getDataTable(list);
    }

    /**
     * 导出用户充值列表
     */
    @RequiresPermissions("biz:recharge:export")
    @Log(title = "用户充值", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizCustomerRecharge bizCustomerRecharge) {
        List<BizCustomerRecharge> list = bizCustomerRechargeService.selectBizCustomerRechargeList(bizCustomerRecharge);
        ExcelUtil<BizCustomerRecharge> util = new ExcelUtil<BizCustomerRecharge>(BizCustomerRecharge.class);
        return util.exportExcel(list, "用户充值数据");
    }

    /**
     * 新增用户充值
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存用户充值
     */
    @ParamValid
    @RequiresPermissions("biz:recharge:add")
    @Log(title = "用户充值", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizCustomerRecharge bizCustomerRecharge) {
        return toAjax(bizCustomerRechargeService.insertBizCustomerRecharge(bizCustomerRecharge));
    }

    /**
     * 修改用户充值
     */
    @RequiresPermissions("biz:recharge:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        BizCustomerRecharge bizCustomerRecharge = bizCustomerRechargeService.selectBizCustomerRechargeById(id);
        mmap.put("bizCustomerRecharge", bizCustomerRecharge);
        return prefix + "/edit";
    }
    /**
     * 用户充值详情
     */
    @RequiresPermissions("biz:recharge:edit")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap) {
        BizCustomerRecharge bizCustomerRecharge = bizCustomerRechargeService.selectBizCustomerRechargeById(id);
        mmap.put("bizCustomerRecharge", bizCustomerRecharge);
        return prefix + "/detail";
    }
    /**
     * 修改保存用户充值
     */
    @ParamValid
    @RequiresPermissions("biz:recharge:edit")
    @Log(title = "用户充值", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizCustomerRecharge bizCustomerRecharge) {
        return toAjax(bizCustomerRechargeService.updateBizCustomerRecharge(bizCustomerRecharge));
    }

    /**
     * 删除用户充值
     */
    @RequiresPermissions("biz:recharge:remove")
    @Log(title = "用户充值", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(bizCustomerRechargeService.deleteBizCustomerRechargeByIds(ids));
    }
}
